package isssr.entity.src;

import java.io.Serializable;
import java.lang.reflect.Field;

public class UserDTO implements Serializable {


	/**
	 * 
	 */
	private static final long serialVersionUID = -4249467754877114373L;
	private String username;
	private String email;
	private String firstname;
	private String lastname;
	private Role   userRole;
	
	
	public UserDTO(	String username,
					String email,
					String firstname,
					String lastname,
					Role role)
	{
		this.username 	= (username == null ? null : new String(username));
		this.email 		= (email == null ? null : new String(email));
		this.firstname 	= (firstname == null ? null : new String(lastname));
		this.lastname 	= (lastname == null ? null : new String(lastname));
		this.userRole 	= role;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getFirstname() {
		return firstname;
	}

	public void setFirstname(String firstname) {
		this.firstname = firstname;
	}

	public String getLastname() {
		return lastname;
	}

	public void setLastname(String lastname) {
		this.lastname = lastname;
	}

	public Role getUserRole() {
		return userRole;
	}

	public void setUserRole(Role userRole) {
		this.userRole = userRole;
	}

	public boolean equals(Object o)
	{
		if(o==null) return false;
		if(o==this) return true;
		

		UserDTO other = (UserDTO) o;
		
		Field[] dataFields = this.getClass().getDeclaredFields();
		
		Object value1;
		Object value2;
		
		for(Field field : dataFields)
		{
			try
			{
				value1 = field.get(this);
				value2 = field.get(other);
				
				if((value1 == null && value2 != null)
						|| ( value1 != null && !value1.equals(value2) ))
					return false;
			}
			catch(Exception ex)
			{
				ex.printStackTrace();
			}
		}
		
		return true;
	}

	@Override
	public String toString()
	{
		
		String output = "UserData[";
		output = output.concat( username != null ? username : "");
		output = output.concat( ", ");
		output = output.concat( email != null ? email : "");
		output = output.concat( ", ");
		output = output.concat( firstname != null ? firstname : "");
		output = output.concat( ", ");
		output = output.concat( lastname != null ? lastname : "");
		output = output.concat( ", ");
		output = output.concat( userRole != null ? userRole.toString() : "");
		output = output.concat( "]");
		
		return output;
	}
}
